package com.jack.controller;

import java.io.File;
import java.io.IOException;

import org.springframework.stereotype.Controller;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class FileuploadController {

	@ResponseBody
	@RequestMapping(method = RequestMethod.POST, name = "/upload")
	public String fileupload(@RequestParam(value="file", required = true) MultipartFile file ) throws IOException {
		byte[] bytes = file.getBytes();
		 File fileTosave = new File(file.getOriginalFilename());
		 FileCopyUtils.copy(bytes, fileTosave);
		 return fileTosave.getAbsolutePath();
	}
}
